package cn.wenhe9.yygh.hosp.controller;

import cn.wenhe9.yygh.common.result.ResultResponse;
import cn.wenhe9.yygh.hosp.service.HospitalSetService;
import cn.wenhe9.yygh.model.hosp.HospitalSet;
import cn.wenhe9.yygh.model.vo.hosp.HospitalSetQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author DuJinliang
 * 2022/2/10
 */
@Api(tags = "医院设置管理")
@RestController
//@CrossOrigin
@RequestMapping("/admin/hosp/hospitalSet")
public class HospitalSetController {
    /**
     * 注入service
     */
    @Resource
    private HospitalSetService hospitalSetService;

    /**
     * 查询医院设置表所有信息
     * @return ResultResponse<List<HospitalSet>>
     */
    @ApiOperation(value = "查询医院设置表所有信息")
    @GetMapping
    public ResultResponse<List<HospitalSet>> findAllHospitalSet(){
        return hospitalSetService.findAllHospSet();
    }

    /**
     * 逻辑删除医院设置
     * @param id 医院设置id
     * @return ResultResponse
     */
    @ApiOperation(value = "逻辑删除医院设置")
    @DeleteMapping("/{id}")
    public ResultResponse removeHospSet(@PathVariable(name = "id") @ApiParam(value = "医院设置 id", name = "id") Long id){
        return hospitalSetService.removeHospSet(id);
    }

    /**
     * 条件查询带分页
     * @param current 当前页
     * @param limit 每页条数
     * @param hospitalSetQueryVo 多条件视图实体
     * @return ResultResponse<Page<HospitalSet>>
     */
    @ApiOperation(value = "条件查询带分页")
    @PostMapping("/page/{current}/{limit}")
    public ResultResponse<Page<HospitalSet>> findHospSetByPage(
            @PathVariable(name = "current") Integer current,
            @PathVariable(name = "limit") Integer limit,
            @RequestBody(required = false) HospitalSetQueryVo hospitalSetQueryVo
    ){
        return hospitalSetService.findHospSetByPage(current, limit, hospitalSetQueryVo);
    }

    /**
     * 添加医院设置
     * @param hospitalSet 医院设置
     * @return ResultResponse
     */
    @ApiOperation("添加医院设置")
    @PostMapping
    public ResultResponse saveHospitalSet(@RequestBody HospitalSet hospitalSet){
        return hospitalSetService.saveHospSet(hospitalSet);
    }

    /**
     * 根据id获取医院设置
     * @param id 医院设置id
     * @return ResultResponse
     */
    @ApiOperation("根据id获取医院设置")
    @GetMapping("/{id}")
    public ResultResponse getHospitalSetById(@PathVariable(name = "id") Long id){
        return hospitalSetService.getHospSetById(id);
    }

    /**
     * 修改医院设置
     * @param hospitalSet 医院设置
     * @return ResultResponse
     */
    @ApiOperation("修改医院设置")
    @PutMapping
    public ResultResponse updateHospitalById(@RequestBody HospitalSet hospitalSet){
        return hospitalSetService.updateHospSetById(hospitalSet);
    }

    /**
     * 批量删除医院设置
     * @param idList id集合
     * @return ResultResponse
     */
    @ApiOperation("批量删除医院设置")
    @DeleteMapping
    public ResultResponse batchRemoveHospital(@RequestBody List<Long> idList){
        return hospitalSetService.batchRemoveHospSetById(idList);
    }

    @PutMapping("/lock/{id}/{status}")
    public ResultResponse lockHospitalSet(
            @PathVariable(name = "id") Long id,
            @PathVariable(name = "status") Integer status
    ){
        return hospitalSetService.lockHospSetById(id, status);
    }

    @PostMapping("/key/{id}")
    public ResultResponse sendKey(@PathVariable(name = "id") Long id){
        hospitalSetService.sendKey(id);
        return null;
    }

 }
